import * as actionTypes from './actionTypes'
import { fromJS } from 'immutable'
import axios from "axios"

const getSearchHotword = (data) => ({
    type: actionTypes.GET_SEARCH_HOTWORD,
    data: fromJS(data),
    totalPage: Math.ceil(data.length / 10)
})

export const searchFocus = () => ({
    type: actionTypes.SEARCH_FOCUS
})
export const searchBlur = () => ({
    type: actionTypes.SEARCH_BLUR
})

export const searchMouseEnter = () => ({
    type: actionTypes.SEARCH_Mouse_Enter
})

export const searchMouseLeave = () => ({
    type: actionTypes.SEARCH_Mouse_Leave
})

export const switchSearchWord = (page) => ({
    type: actionTypes.SWITCH_SEARCH_WORD,
    page
})

export const getSearchHotWord = () => {
    return async (dispatch)=>{
        const { data: {data} } = await axios.get("/api/headerList.json")
        dispatch(getSearchHotword(data))
    }
}